

local attackIconFiles = {
    ['普通'] = [[UI\Widgets\Console\Human\infocard-neutral-attack-melee.blp]],
    ['穿刺'] = [[UI\Widgets\Console\Human\infocard-neutral-attack-piercing.blp]],
    ['法术'] = [[UI\Widgets\Console\Human\infocard-neutral-attack-melee.blp]],
    ['攻城'] = [[UI\Widgets\Console\Human\infocard-neutral-attack-siege.blp]],
    ['混乱'] = [[UI\Widgets\COnsole\Human\infocard-neutral-attack-chaos.blp]],
    ['近战'] = [[UI\Widgets\Console\Human\infocard-neutral-attack-melee.blp]],
    ['魔法'] = [[UI\Widgets\COnsole\Human\infocard-neutral-attack-magic.blp]],
    ['未知'] = [[UI\Widgets\Console\Human\infocard-neutral-attack-melee.blp]],
    ['英雄'] = [[UI\Widgets\Console\Human\infocard-neutral-attack-hero.blp]],
}

--攻击按钮
class.attack_button = extends(class.button)
{
    reload = true,
    new = function (parent,icon,x,y,w,h)
        local panel = class.attack_button:builder 
        {
            parent = parent,
            x = x,
            y = y,
            w = w,
            h = h,
            normal_image = attackIconFiles['英雄'],
        }
        return panel
    end,
    init = function (self)
        class.button.init(self)
        self.title = self:add_text('攻击力:',self.w,3,150,20,8,4)
        self.text = self:add_text('1000',self.w+5,23,150,20,8,4)
        
        self.title:set_color(0xffffff00)
        
        return self
    end,
    update = function(self,unit)
        local key1 = '基础攻击'
        local key2 = '额外攻击'
        local key3 = '基础攻击%'
        local base = math.floor(unit:get(key1))
        local ext = math.floor(unit:get(key2))
        local rate = math.floor(unit:get(key3))
        local text = ''
        if unit:get_data('默认伤害')=='魔法' then
            self:set_normal_image(attackIconFiles['魔法'])
        elseif unit:get_data('默认伤害')=='混合' then
            self:set_normal_image(attackIconFiles['混乱'])
        else
            self:set_normal_image(attackIconFiles['英雄'])
        end
        base = format_number3(base)
        if ext > 0 then 
            text = ("%s + |cff00ff00%s|r"):format(base, format_number3(ext))
        elseif ext<0 then
            text = ("%s - |cffff0000%s|r"):format(base, format_number3(ext))
        else
            text = base
        end
        self.text:set_text(text)

    end,
    on_button_mouse_enter = function(self)
        local hero = ac.unit.localunit()
        if not hero then
            return
        end
        local ad = get_ex_attack(hero,'物理')
        local ap = get_ex_attack(hero,'魔法')
        local tip = ''
        tip = ('%s|n|cff999999攻击类型：|r%s'):format(tip,hero:get_data('默认伤害') or '物理')
        tip = ('%s|n|cff999999输出类型：|r%s'):format(tip,hero:get_data('默认输出') or '普攻')
        tip = ('%s|n|cff999999物理攻击：|r%0.f'):format(tip,ad)
        tip = ('%s|n|cff999999魔法攻击：|r%0.f'):format(tip,ap)
        tip = ('%s|n|cff999999攻击范围：|r%0.f'):format(tip,hero:get('攻击距离'))
        tip = ('%s|n|cff999999攻击间隔：|r%0.1f'):format(tip,hero:get('攻击间隔'))
        tip = ('%s|n|cff999999攻击速度：|r%0.f%%'):format(tip,hero:get('攻击速度'))
        tip = ('%s|n|cff999999冷却速度：|r%0.f%%'):format(tip,hero:get('冷却速度'))
        tip = ('%s|n|n|cff00ff00如果冷却比攻速高超过部分会适当提升伤害|r'):format(tip)

        self:tooltip(('基础攻击：%0.f'):format(hero:get('攻击')),tip)
        
    end,
}